package com.quyou.funtour.controller;

import com.quyou.funtour.bean.ResultInfo;
import com.quyou.funtour.po.UserParticipateActivityPo;
import com.quyou.funtour.service.UserParticipateActivityService;
import com.quyou.funtour.vo.UserParticipateActivityVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/participateActivityService")
@CrossOrigin
public class UserParticipateActivityController {

    @Autowired
    private UserParticipateActivityService participateActivityService;

    /**
     * 根据活动id获取参与对象
     * @param id
     * @return
     */
    @GetMapping("/getUserById/{aid}")
    @ResponseBody
    public ResultInfo getUserById(@PathVariable("aid") String id){
        List<UserParticipateActivityVo> list = participateActivityService.getList(id);
        return ResultInfo.ok(list);
    }

    /**
     * 删除预约用户
     * @param id
     * @return
     */
    @GetMapping("/deleteUser/{id}")
    @ResponseBody
    public ResultInfo deleteUser(@PathVariable("id") String id){
        boolean b = participateActivityService.removeById(id);
        if(b){
            return ResultInfo.ok("删除成功");
        }else {
            return ResultInfo.no("删除失败");
        }
    }

    /**
     * 修改预约用户信息
     * @param userParticipateActivityPou
     * @return
     */
    @GetMapping("/updateUser")
    @ResponseBody
    public ResultInfo updateUser(UserParticipateActivityPo userParticipateActivityPou){
        boolean b = participateActivityService.updateById(userParticipateActivityPou);
        if(b){
            return ResultInfo.ok("修改成功");
        }else {
            return ResultInfo.no("修改失败");
        }
    }

    /**
     * 根据预约id获取预约用户的信息
     * @param id
     * @return
     */
    @GetMapping("/getUPCById/{id}")
    @ResponseBody
    public ResultInfo getUPCById(@PathVariable("id") String id){
        UserParticipateActivityPo byId = participateActivityService.getById(id);
        if(byId!=null){
            byId.setCreateTime(null);
            return ResultInfo.ok(byId);
        }else {
            return ResultInfo.no("获取失败");
        }
    }

}
